package com.etl.dataflow.common.enums;

import java.util.NoSuchElementException;

/**
 * 任务状态枚举类
 *
 * @author dx
 * @since 2022/4/20
 */
public enum TaskStateEnum {

    /**
     * 任务运行中
     */
    RUNNING(1, "运行中"),

    /**
     * 已被停止
     */
    TERMINATED(2, "已手动停止"),

    /**
     * 正常结束
     */
    FINISHED(3, "正常结束"),

    /**
     * 致命错误
     */
    FATAL_ERROR(4, "致命错误"),

    /**
     * 等待执行
     */
    WAITING(5, "等待执行"),

    /**
     * 执行超时
     */
    TIMEOUT(6, "执行超时");

    private final int value;
    private String msg;

    TaskStateEnum(int value, String msg) {
        this.value = value;
        this.msg = msg;
    }

    public static TaskStateEnum of(int value) {
        TaskStateEnum[] values = TaskStateEnum.values();
        for (TaskStateEnum taskStateEnum : values) {
            if (taskStateEnum.getValue() == value) {
                return taskStateEnum;
            }
        }
        throw new NoSuchElementException("没有值为 " + value + " 的任务状态");
    }

    public int getValue() {
        return value;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
